<template>
	<view class="page">
		<u-sticky>
			<view class="placeholder-bar" :style="{height: `${statusBarHeight}px`}"></view>
		</u-sticky>
		<u-sticky :offsetTop="statusBarHeight">
			<view class="top-bar">
				<u-icon name="list" :size="20" color="#232832" @click="openPopup"></u-icon>
			</view>
		</u-sticky>
		<z-paging ref="paging" fixed refresher-only class="paging" :data-key="4"
			:style="{top: `${statusBarHeight + 44}px`, bottom: `${safeAreaBottom + 60}px`}" refresher-vibrate
			refresher-background="transparent" safe-area-inset-bottom @query="onRefresh" show-refresher-when-reload
			show-refresher-update-time refresher-update-time-key="tab4" @scroll="onScroll">
			<view class="content">
				<view class="user">
					<view class="avatar">
						<u-avatar :src="avatar" :size="64"></u-avatar>
					</view>
					<view class="userinfo">
						<view class="nickname">{{ nickname }}</view>
						<view class="ip">IP：{{ city }}</view>
						<view class="sex">
							<text class="icon-man" style="margin-right: 5px;color: #1e90ff;" v-if="sex == '1'"></text>
							<text class="icon-girl" style="margin-right: 5px;color: #e84393;" v-if="sex == '0'"></text>
							<text>{{ age }}岁</text>
						</view>
					</view>
				</view>
				<view class="banner">
					<view class="items">
						<view class="value-item" v-for="(item, index) in data" :key="index" @click="goDetail(index)">
							<view class="value">{{ utils.formatVal(item.value) }}</view>
							<view class="label">{{ item.label }}</view>
						</view>
					</view>
				</view>

				<view class="panel">
					<view class="panel-header">
						<view class="panel-header__title">我的作品</view>
						<view class="panel-header__value">
							<text>更多</text>
							<u-icon name="arrow-right" color="#FFFFFF" :size="16"></u-icon>
						</view>
					</view>
					<view class="panel-content">
						<view class="panel-content__items">
							<view class="panel-content__items-item" v-for="i in 2" :key="i">
								<view class="image-item" :style="{width: `${imgSize}px`, height: `${imgSize}px`}">
									<image src="../../../static/1.png" mode="scaleToFill"></image>
								</view>
								<view class="data">
									<view>
										<text class="icon-thumb-active"></text>
										<text class="value">8.6K</text>
									</view>
									<view>
										<text class="icon-comment-s"></text>
										<text class="value">2.5K</text>
									</view>
									<view>
										<text class="icon-view"></text>
										<text class="value">52</text>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>

				<view class="panel">
					<view class="panel-header">
						<view class="panel-header__title">我的图库</view>
						<view class="panel-header__value">
							<text>更多</text>
							<u-icon name="arrow-right" color="#787B86" :size="16"></u-icon>
						</view>
					</view>
					<view class="panel-content">
						<view class="panel-content__items">
							<view class="panel-content__items-item" v-for="i in 2" :key="i">
								<view class="image-item" :style="{width: `${imgSize}px`, height: `${imgSize}px`}">
									<image src="../../../static/1.png" mode="scaleToFill"></image>
								</view>
								<view class="info">
									<view class="name">旅行生活</view>
									<view class="date">更新于2023-05-20</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</z-paging>

		<u-popup mode="left" :show="popup" @close="closePopup()" :zIndex="99999" :safeAreaInsetBottom="false">
			<view class="popup-content"
				:style="{paddingBottom: `${safeAreaBottom}px`, paddingTop: `${statusBarHeight}px`}">
				<view class="popup-content__top">
					<u-avatar src="/static/1.png" :size="64"></u-avatar>
					<view class="nickname">金金小张</view>
					<view class="uid">ID:256879348</view>
					<view class="sign">
						<view>
							<text v-for="i in 15" :key="i">这是个性签名</text>
						</view>
					</view>
				</view>
				<view class="popup-content__menu">
					<view class="popup-content__menu-item" v-for="(u, index) in user" :key="index" @click="goMenu(u)">
						<u-icon :name="u.icon" color="#787B86" :size="20"></u-icon>
						<view class="menu-label">{{ u.label }}</view>
					</view>
					<u-gap height="2px" bgColor="#F4F4F7" :marginTop="15" :marginBottom="15"></u-gap>
					<view class="popup-content__menu-item" @click="goMenu({url: '/pages/common/msg'})">
						<u-icon name="chat" color="#787B86" :size="20"></u-icon>
						<view class="menu-label">消息设置</view>
					</view>
					<view class="popup-content__menu-item" @click="goMenu({url: '/pages/common/safe'})">
						<u-icon name="lock" color="#787B86" :size="20"></u-icon>
						<view class="menu-label">账户安全</view>
					</view>
					<view class="popup-content__menu-item" @click="loginOut()">
						<view class="menu-icon icon-exit"></view>
						<view class="menu-label">退出</view>
					</view>
				</view>
				<view class="popup-footer">
					<view class="popup-footer__menu" v-for="(item, index) in items" :key="index" @click="goItem(index)">
						<view class="icon" :class="item.icon"></view>
						<view class="menu-label">{{ item.label }}</view>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import mixins from '@/mixins/index.js'
	export default {
		mixins: [mixins],
		data() {
			return {
				popup: false,
				value: 30,
				user: [{
						icon: 'account',
						label: '个人资料',
						url: '/pages/common/info'
					},
					{
						icon: 'man-add',
						label: '联系人',
						url: '/pages/common/contact?type=2'
					},
					{
						icon: 'tags',
						label: '我的草稿',
						url: '/pages/common/draft'
					},
				],
				modal: false,
				items: [{
						icon: 'icon-certified',
						label: '实名认证'
					},
					{
						icon: 'icon-setting',
						label: '系统设置'
					},
					{
						icon: 'icon-scan',
						label: '扫一扫'
					}
				],
				data: [{
						value: 1624,
						label: '关注'
					},
					{
						value: 12071,
						label: '粉丝'
					},
					{
						value: 44069,
						label: '获赞'
					}
				]
			}
		},
		computed: {
			utils() {
				return uni.utils
			},
			imgSize() {
				return ((uni.getSystemInfoSync().windowWidth - 48 - 18 - 20) / 2)
			},
			avatar() {
				return this.$FILE_URL + uni.$store.get('avatar')
			},
			nickname() {
				return uni.$store.get('nickname')
			},
			id() {
				return uni.$store.get('id')
			},
			city() {
				return uni.$store.get('city')
			},
			sex() {
				return uni.$store.get('sex')
			},
			age() {
				return new Date().getFullYear() - uni.$store.get('birth').split('-')[0]
			}
		},
		created() {
			console.log('init tab4', uni.config);
		},
		methods: {
			goDetail(type) {
				if (type != 2) {
					uni.navigateTo({
						url: `/pages/common/contact?type=${type}`
					})
				}
			},
			openPopup() {
				this.popup = true
			},
			closePopup() {
				this.popup = false
			},
			loginOut() {
				uni.$emit('showLoginoutModal')
			},
			goMenu(item) {
				this.popup = false
				if (item.url) {
					uni.navigateTo({
						url: item.url
					})
				}
			},
			goItem(index) {
				this.popup = false
				if (index == 0) {
					uni.navigateTo({
						url: '/pages/authentication/front'
					})
				} else if (index == 1) {
					uni.navigateTo({
						url: '/pages/common/setting'
					})
				} else if (index == 2) {
					uni.scanCode({
						autoDecodeCharSet: true,
						autoZoom: true,
						scanType: ['qrcode'],
						sound: 'default',
						onlyFromCamera: false,
						success: (rs) => {
							console.log(rs);
						}
					})
				}
			},
		},
		onBackPress(e) {
			if (e.from == 'backbutton' && this.popup) {
				this.popup = false
			}
		}
	}
</script>

<style scoped lang="scss">
	@import url('./common.scss');

	@mixin userinfo {
		.nickname {
			margin-top: 18px;
			color: #232832;
			font-size: 20px;
			font-weight: 500;
			line-height: 23px;
		}

		.ip,
		.sex {
			display: inline-block;
			background-color: #FFFFFF;
			margin-top: 6px;
			margin-right: 10px;
			padding: 4px 6px;
			border-radius: 2px;
			color: #232832;
			font-size: 10px;
			line-height: 10px;
			font-weight: 400;
		}
	}

	.page {
		background-color: #F4F4F7;
	}

	.content {
		padding: 0 14px;
		box-sizing: border-box;
	}

	.top-bar {
		display: flex;
		justify-content: flex-start;
		align-items: center;
		height: 44px;
		padding: 0 16px;
		box-sizing: border-box;
		background-color: #F4F4F7;

		.icon {
			color: #232832 !important;
		}
	}

	.popup-content {
		width: 75vw;
		height: 100%;
		background-color: #FFFFFF;
		box-sizing: border-box;

		&__top {
			padding: 22px 22px 12px;
			box-sizing: border-box;

			@include userinfo;

			.sign {
				margin-top: 10px;
				color: #232832;
				font-size: 12px;
				line-height: 16px;
			}
		}

		&__menu {
			padding: 0 14px;

			&-item {
				display: flex;
				align-items: center;
				justify-content: flex-start;
				padding: 10px;
			}

			.menu-label {
				margin-left: 15px;
				color: #232832;
				font-size: 15px;
				font-weight: 400;
				line-height: 18px;
			}

			.menu-icon {
				padding: 1px;
				color: #787B86;
				font-size: 18px;
			}
		}
	}

	.popup-footer {
		position: absolute;
		bottom: 80px;
		display: flex;
		align-items: center;
		width: 100%;
		padding: 10px 0;

		&__menu {
			display: flex;
			flex-direction: column;
			align-items: center;
			width: 100%;
		}

		.icon {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 36px;
			height: 36px;
			background-color: #F4F4F7;
			border-radius: 50%;
			color: #232832;
			font-size: 16px;
		}

		.menu-label {
			margin-top: 6px;
			color: #787B86;
			font-size: 12px;
			font-weight: 400;
			line-height: 14px;
		}
	}

	.user {
		display: flex;
		align-items: center;
		justify-content: flex-start;
		padding: 10px 8px;

		.userinfo {
			flex: 1;
			margin-left: 15px;
		}

		@include userinfo;

		.nickname {
			margin-top: 0;
		}
	}

	.banner {
		background-color: #FFFFFF;
		border-radius: 15px;
		padding: 10px 0;
		margin: 20px 8px;

		.items {
			display: flex;
			align-items: center;
			padding: 10px;
		}

		.value-item {
			width: 100%;
			text-align: center;
		}

		.value {
			color: #232832;
			font-size: 20px;
			line-height: 23px;
			font-weight: 500;
		}

		.label {
			margin-top: 10px;
			color: #787B86;
			font-size: 12px;
			line-height: 14px;
			font-weight: 400;
		}
	}

	.panel {
		background-color: #FFFFFF;
		margin: 0 10px;
		border-radius: 15px;
		padding-bottom: 15px;
		margin-bottom: 20px;

		.panel-header {
			display: flex;
			align-items: center;
			padding: 10px 14px;

			&__title {
				flex: 1;
				color: #232832;
				font-size: 15px;
				line-height: 18px;
				font-weight: 500;
			}

			&__value {
				display: flex;
				align-items: center;
				color: #787B86;
				font-size: 12px;
				line-height: 14px;
				font-weight: 400;
			}
		}

		.panel-content {
			width: 100%;
			padding-top: 10px;

			&__items {
				display: flex;
				align-items: center;
				justify-content: center;
			}

			&__items-item {
				position: relative;
				margin: 0 5px;
			}

			image {
				width: 100%;
				height: 100%;
				border-radius: 10px;
			}

			.data {
				position: absolute;
				display: flex;
				align-items: center;
				justify-content: flex-start;
				bottom: 0;
				left: 0;
				width: 100%;
				height: 21px;
				background-color: rgba(0, 0, 0, .3);

				&>view {
					display: flex;
					align-items: center;
					margin-left: 5px;
					color: #FFFFFF;
				}

				.value {
					font-size: 12px;
					line-height: 14px;
					font-weight: 400;
				}

				[class*=icon] {
					margin-right: 3px;
					font-size: 12px;
				}
			}

			.info {
				display: flex;
				flex-direction: column;
				align-items: flex-start;
				margin-top: 10px;
				margin-left: 5px;
				color: #232832;

				.name {
					flex: 1;
					font-size: 12px;
					font-weight: 400;
					line-height: 14px;
				}

				.date {
					margin-top: 5px;
					color: #B9BCC3;
					font-size: 10px;
					line-height: 12px;
					font-weight: 400;
				}
			}
		}
	}
</style>